package com.iknow.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Resources;
import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.os.IBinder;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.app.IKnowSystemConfig;
import com.iknow.task.GenericTask;
import com.iknow.task.TaskAdapter;
import com.iknow.task.TaskListener;
import com.iknow.task.TaskParams;
import com.iknow.task.TaskResult;
import com.iknow.util.Loger;
import com.iknow.util.Regex;
import com.iknow.util.StringUtil;
import com.iknow.xmpp.service.aidl.IXmppFacade;
import com.iknow.xmpp.service.aidl.IXmppFacade.Stub;
import com.mobclick.android.MobclickAgent;
import com.xmpp.task.LoginAsyncTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jivesoftware.smack.util.StringUtils;

public class RegisterActivity extends Activity
{
  private static final Intent SERVICE_INTENT = new Intent();
  private View.OnClickListener RegisterBtnClickListener;
  private boolean mBinded;
  private XmppServiceConnection mConn;
  private Context mContext;
  private AutoCompleteTextView mEmailEditText;
  private LoginAsyncTask mLoginTask;
  private ProgressDialog mProgressDialog;
  private EditText mPwdEdit;
  private Button mRegisterButton;
  private RegisterTask mRegisterTask;
  private boolean mRegistered;
  private TaskListener mTaskListener;
  private TextView mTitle;
  private IXmppFacade mXmppFacade;

  static
  {
    SERVICE_INTENT.setComponent(new ComponentName("com.iknow", "com.iknow.xmpp.service.IKnowXmppService"));
    SERVICE_INTENT.setAction("LOGIN_STARTED");
  }

  public RegisterActivity()
  {
    this.mConn = new XmppServiceConnection(this, null);
    this.RegisterBtnClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        if (!(IKnow.IsNetAviable()))
          Toast.makeText(RegisterActivity.access$0(this.this$0), RegisterActivity.access$0(this.this$0).getResources().getString(2131361878), 0).show();
        while (true)
        {
          String str3;
          while (true)
          {
            while (true)
            {
              do
                while (true)
                {
                  return;
                  if (!(RegisterActivity.access$1(this.this$0)))
                    break;
                  RegisterActivity.access$2(this.this$0);
                }
              while ((RegisterActivity.access$3(this.this$0) != null) && (RegisterActivity.access$3(this.this$0).getStatus() == AsyncTask.Status.RUNNING));
              str1 = RegisterActivity.access$4(this.this$0).getText().toString();
              if (str1.equalsIgnoreCase("im_qplus"))
                break label190;
              if (!(StringUtil.isEmpty(str1)))
                break;
              Toast.makeText(RegisterActivity.access$0(this.this$0), "请先填写邮箱地址", 0).show();
            }
            str3 = str1.trim();
            Matcher localMatcher = Regex.EMAIL_ADDRESS_PATTERN.matcher(str3);
            if ((StringUtil.isEmpty(str3)) || (localMatcher.matches()))
              break;
            Toast.makeText(RegisterActivity.access$0(this.this$0), "请先填写邮箱地址", 0).show();
          }
          String str1 = StringUtil.getMD5String(str3);
          label190: String str2 = RegisterActivity.access$5(this.this$0).getText().toString();
          if (StringUtil.isEmpty(str2))
            str2 = "111111";
          RegisterActivity.access$6(this.this$0, new RegisterActivity.RegisterTask(this.this$0, null));
          RegisterActivity.access$3(this.this$0).setListener(RegisterActivity.access$7(this.this$0));
          TaskParams localTaskParams = new TaskParams();
          localTaskParams.put("name", str1);
          localTaskParams.put("password", str2);
          localTaskParams.put("email", RegisterActivity.access$5(this.this$0).getText().toString());
          RegisterActivity.RegisterTask localRegisterTask = RegisterActivity.access$3(this.this$0);
          TaskParams[] arrayOfTaskParams = new TaskParams[1];
          arrayOfTaskParams[0] = localTaskParams;
          localRegisterTask.execute(arrayOfTaskParams);
        }
      }
    };
    this.mTaskListener = new TaskAdapter(this)
    {
      public String getName()
      {
        return "UserInfo";
      }

      public void onCancelled()
      {
        Loger.i("RegisterTask", "RegisterTask is cancel!!");
      }

      public void onPostExecute(, TaskResult paramTaskResult)
      {
        if (paramGenericTask instanceof RegisterActivity.RegisterTask)
          if (paramTaskResult == TaskResult.OK)
            RegisterActivity.access$2(this.this$0);
        while (true)
        {
          while (true)
          {
            do
              while (true)
              {
                return;
                RegisterActivity.access$9(this.this$0, ((RegisterActivity.RegisterTask)paramGenericTask).getMsg());
              }
            while (!(paramGenericTask instanceof LoginAsyncTask));
            if (paramTaskResult != TaskResult.OK)
              break;
            RegisterActivity.access$10(this.this$0);
          }
          RegisterActivity.access$9(this.this$0, ((LoginAsyncTask)paramGenericTask).getErrorMessage());
        }
      }

      public void onPreExecute()
      {
        RegisterActivity.access$8(this.this$0, "正在注册，请稍等");
      }

      public void onProgressUpdate(, Object paramObject)
      {
      }
    };
  }

  private void initView()
  {
    this.mEmailEditText = ((AutoCompleteTextView)findViewById(2131296279));
    this.mRegisterButton = ((Button)findViewById(2131296278));
    this.mRegisterButton.setOnClickListener(this.RegisterBtnClickListener);
    this.mPwdEdit = ((EditText)findViewById(2131296280));
    this.mEmailEditText.addTextChangedListener(new EmailTextWatcher(this, null));
    this.mTitle = ((TextView)findViewById(2131296343));
    this.mTitle.setText("注册");
    this.mTitle.setVisibility(0);
    findViewById(2131296342).setVisibility(8);
    findViewById(2131296344).setVisibility(8);
  }

  private void login()
  {
    this.mLoginTask = new LoginAsyncTask();
    this.mLoginTask.setListener(this.mTaskListener);
    TaskParams localTaskParams = new TaskParams();
    localTaskParams.put("xmpp", this.mXmppFacade);
    String str1 = StringUtils.parseName(IKnow.mSystemConfig.getString("account_username"));
    String str2 = IKnow.mSystemConfig.getString("account_password");
    localTaskParams.put("jid", str1);
    localTaskParams.put("password", str2);
    localTaskParams.put("email", this.mEmailEditText.getText().toString());
    LoginAsyncTask localLoginAsyncTask = this.mLoginTask;
    TaskParams[] arrayOfTaskParams = new TaskParams[1];
    arrayOfTaskParams[0] = localTaskParams;
    localLoginAsyncTask.execute(arrayOfTaskParams);
  }

  private void onLoginSuccess()
  {
    startService(SERVICE_INTENT);
    if (this.mProgressDialog != null)
      this.mProgressDialog.dismiss();
    Toast.makeText(this, "欢迎加入iKnow圈子", 1).show();
    MobclickAgent.onEvent(this, "register");
    startActivity(new Intent(this, SearchFriendsOptionActivity.class));
    finish();
  }

  private void onResigterSuccess()
  {
    if (!(this.mBinded))
      this.mBinded = bindService(SERVICE_INTENT, this.mConn, 1);
    this.mRegistered = true;
  }

  private void onSubmitBegin(String paramString)
  {
    if (this.mProgressDialog == null)
      this.mProgressDialog = new ProgressDialog(this);
    if (this.mProgressDialog.isShowing());
    while (true)
    {
      return;
      this.mProgressDialog.setCancelable(false);
      this.mProgressDialog.setMessage(paramString);
      this.mProgressDialog.show();
    }
  }

  private void onSubmitFailure(String paramString)
  {
    if (this.mBinded)
    {
      unbindService(this.mConn);
      this.mBinded = false;
    }
    if (this.mProgressDialog != null)
      this.mProgressDialog.dismiss();
    Toast.makeText(this, paramString, 0).show();
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903119);
    this.mContext = this;
    initView();
  }

  protected void onDestroy()
  {
    if ((this.mRegisterTask != null) && (this.mRegisterTask.getStatus() == AsyncTask.Status.RUNNING))
      this.mRegisterTask.cancel(true);
    super.onDestroy();
  }

  protected void onPause()
  {
    if (this.mBinded)
    {
      unbindService(this.mConn);
      this.mBinded = false;
    }
    super.onPause();
  }

  protected void onResume()
  {
    super.onResume();
  }

  private class EmailTextWatcher
  implements TextWatcher
  {
    ArrayAdapter<String> adapt = null;

    public void afterTextChanged()
    {
    }

    public void beforeTextChanged(, int paramInt1, int paramInt2, int paramInt3)
    {
    }

    public void onTextChanged(, int paramInt1, int paramInt2, int paramInt3)
    {
      String str1 = paramCharSequence.toString();
      if (StringUtil.isEmpty(str1));
      while (true)
      {
        String str2;
        do
        {
          return;
          str2 = str1.substring(paramInt1);
        }
        while ((StringUtil.isEmpty(str2)) || (!(str2.equalsIgnoreCase("@"))));
        String[] arrayOfString = new String[7];
        arrayOfString[0] = str1 + "163.com";
        arrayOfString[1] = str1 + "sina.com";
        arrayOfString[2] = str1 + "qq.com";
        arrayOfString[3] = str1 + "126.com";
        arrayOfString[4] = str1 + "gmail.com";
        arrayOfString[5] = str1 + "hotmail.com";
        arrayOfString[6] = str1 + "sohu.com";
        this.adapt = new ArrayAdapter(this.this$0, 17367050, arrayOfString);
        RegisterActivity.access$4(this.this$0).setAdapter(this.adapt);
        RegisterActivity.access$4(this.this$0).setThreshold(paramInt1);
      }
    }
  }

  private class RegisterTask extends GenericTask
  {
    private String mMsg = null;

    // ERROR //
    protected TaskResult _doInBackground()
    {
      // Byte code:
      //   0: aload_1
      //   1: iconst_0
      //   2: aaload
      //   3: astore_2
      //   4: aload_2
      //   5: ldc 31
      //   7: invokevirtual 37	com/iknow/task/TaskParams:getString	(Ljava/lang/String;)Ljava/lang/String;
      //   10: astore 5
      //   12: aload_2
      //   13: ldc 39
      //   15: invokevirtual 37	com/iknow/task/TaskParams:getString	(Ljava/lang/String;)Ljava/lang/String;
      //   18: astore 6
      //   20: new 41	org/jivesoftware/smack/XMPPConnection
      //   23: dup
      //   24: new 43	org/jivesoftware/smack/ConnectionConfiguration
      //   27: dup
      //   28: ldc 45
      //   30: sipush 5222
      //   33: invokespecial 48	org/jivesoftware/smack/ConnectionConfiguration:<init>	(Ljava/lang/String;I)V
      //   36: invokespecial 51	org/jivesoftware/smack/XMPPConnection:<init>	(Lorg/jivesoftware/smack/ConnectionConfiguration;)V
      //   39: astore 7
      //   41: aload 7
      //   43: invokevirtual 54	org/jivesoftware/smack/XMPPConnection:connect	()V
      //   46: new 56	org/jivesoftware/smack/AccountManager
      //   49: dup
      //   50: aload 7
      //   52: invokespecial 59	org/jivesoftware/smack/AccountManager:<init>	(Lorg/jivesoftware/smack/Connection;)V
      //   55: aload 5
      //   57: aload 6
      //   59: invokevirtual 63	org/jivesoftware/smack/AccountManager:createAccount	(Ljava/lang/String;Ljava/lang/String;)V
      //   62: getstatic 69	com/iknow/IKnow:mSystemConfig	Lcom/iknow/app/IKnowSystemConfig;
      //   65: ldc 71
      //   67: new 73	java/lang/StringBuilder
      //   70: dup
      //   71: aload 5
      //   73: invokestatic 79	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
      //   76: invokespecial 82	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
      //   79: ldc 84
      //   81: invokevirtual 88	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   84: ldc 45
      //   86: invokevirtual 88	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   89: invokevirtual 92	java/lang/StringBuilder:toString	()Ljava/lang/String;
      //   92: invokevirtual 97	com/iknow/app/IKnowSystemConfig:setString	(Ljava/lang/String;Ljava/lang/String;)V
      //   95: getstatic 69	com/iknow/IKnow:mSystemConfig	Lcom/iknow/app/IKnowSystemConfig;
      //   98: ldc 99
      //   100: aload 6
      //   102: invokevirtual 97	com/iknow/app/IKnowSystemConfig:setString	(Ljava/lang/String;Ljava/lang/String;)V
      //   105: aload 7
      //   107: invokevirtual 102	org/jivesoftware/smack/XMPPConnection:disconnect	()V
      //   110: getstatic 108	com/iknow/task/TaskResult:OK	Lcom/iknow/task/TaskResult;
      //   113: astore 4
      //   115: goto +71 -> 186
      //   118: astore 8
      //   120: ldc 110
      //   122: aload 8
      //   124: invokevirtual 113	org/jivesoftware/smack/XMPPException:getMessage	()Ljava/lang/String;
      //   127: invokestatic 118	com/iknow/util/Loger:e	(Ljava/lang/String;Ljava/lang/String;)V
      //   130: aload 8
      //   132: invokevirtual 113	org/jivesoftware/smack/XMPPException:getMessage	()Ljava/lang/String;
      //   135: ldc 120
      //   137: invokevirtual 124	java/lang/String:indexOf	(Ljava/lang/String;)I
      //   140: bipush 255
      //   142: if_icmpeq +17 -> 159
      //   145: aload_0
      //   146: ldc 126
      //   148: putfield 20	com/iknow/activity/RegisterActivity$RegisterTask:mMsg	Ljava/lang/String;
      //   151: getstatic 129	com/iknow/task/TaskResult:FAILED	Lcom/iknow/task/TaskResult;
      //   154: astore 4
      //   156: goto +30 -> 186
      //   159: aload_0
      //   160: ldc 131
      //   162: putfield 20	com/iknow/activity/RegisterActivity$RegisterTask:mMsg	Ljava/lang/String;
      //   165: goto -14 -> 151
      //   168: astore_3
      //   169: aload_3
      //   170: invokevirtual 134	com/iknow/http/HttpException:printStackTrace	()V
      //   173: aload_0
      //   174: aload_3
      //   175: invokevirtual 135	com/iknow/http/HttpException:getMessage	()Ljava/lang/String;
      //   178: putfield 20	com/iknow/activity/RegisterActivity$RegisterTask:mMsg	Ljava/lang/String;
      //   181: getstatic 129	com/iknow/task/TaskResult:FAILED	Lcom/iknow/task/TaskResult;
      //   184: astore 4
      //   186: aload 4
      //   188: areturn
      //
      // Exception table:
      //   from	to	target	type
      //   41	105	118	org/jivesoftware/smack/XMPPException
      //   4	41	168	com/iknow/http/HttpException
      //   41	105	168	com/iknow/http/HttpException
      //   105	165	168	com/iknow/http/HttpException
    }

    public String getMsg()
    {
      return this.mMsg;
    }
  }

  private class XmppServiceConnection
  implements ServiceConnection
  {
    public void onServiceConnected(, IBinder paramIBinder)
    {
      RegisterActivity.access$11(this.this$0, IXmppFacade.Stub.asInterface(paramIBinder));
      RegisterActivity.access$12(this.this$0);
    }

    public void onServiceDisconnected()
    {
      RegisterActivity.access$11(this.this$0, null);
    }
  }
}